<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Enrolment_model extends AppModel {
    var $_primary_key = ENROLMENT_ENROL_ID;
    var $_tablename = ENROLMENT;
    var $_mapping = array(
                           array('admin_id' => ENROLMENT_FRANCHISE_ID),
                           array('id' => ENROLMENT_ENROL_ID),
                           array('enrol_type' => ENROLMENT_ENROL_TYPE),
                           array('course_id' => ENROLMENT_COURSE_ID),
                           array('class_id' => ENROLMENT_CLASS_ID),
                           array('term_id' => ENROLMENT_TERM_ID),
                           array('class_name' => ENROLMENT_CLASS_NAME),
                           array('name' => ENROLMENT_NAME),
                           array('surname' => ENROLMENT_SURNAME),
                           array('dob' => ENROLMENT_DOB),
                           array('sex' => ENROLMENT_SEX),
                           array('mother' => ENROLMENT_MOTHER),
                           array('father' => ENROLMENT_FATHER),
                           array('street' => ENROLMENT_STREET),
                           array('street2' => ENROLMENT_STREET2),
                           array('postal_code' => ENROLMENT_POSTAL_CODE),
                           array('city' => ENROLMENT_CITY),
                           array('phone' => ENROLMENT_PHONE),
                           array('mobile' => ENROLMENT_MOBILE),
                           array('email' => ENROLMENT_EMAIL),
                           array('med_cond' => ENROLMENT_MED_COND),
                           array('comments' => ENROLMENT_COMMENTS),
                           array('pay_opt' => ENROLMENT_PAY_OPT),
                           array('date' => ENROLMENT_DATE),
                           array('amount' => ENROLMENT_AMOUNT),
                           array('card_type' => ENROLMENT_CARD_TYPE),
                           array('card_num' => ENROLMENT_CARD_NUM),
                           array('card_name' => ENROLMENT_CARD_NAME),
                           array('card_exp' => ENROLMENT_CARD_EXP),
                           array('mkt_src' => ENROLMENT_MKT_SRC),
                           array('term' => ENROLMENT_TERM),
                           array('referred' => ENROLMENT_REFERRED),
                        );
    public function Enrolment_model(){
        parent::AppModel();
    }
    
    function get_last_id(){
        $this->db->select('MAX('.$this->_primary_key.') AS last_id');
        $this->db->where(ENROLMENT_FRANCHISE_ID, $this->admin_id);
        $result = $this->db->get($this->_tablename)->row();
        if(empty($result->last_id))
            return 1;
        else
            return $result->last_id + 1;
    }
}